﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WuHouCiClient
{
    //需要的数据结构
    struct accountInfo
    {
        string account;//32 bytes
        string password;
    }

    struct playerInfo
    {
        int id;
        int modelId;
        string name;
    }

    class Register_login:SuperLogic
    {
        public int Id = 1;
 
        //byte[] serialize() { }

        public override void deserialize(byte[] source)
        {
            //将前四个字节转换成int类型
            byte[] bid = new byte[4];
            for(int i = 0; i < 4;i ++)
            {
                bid[i] = source[i];
            }
            int id = CProtocol.byte4ToInt(bid);

            byte[] result = new byte[source.Length - 4];
            for (int i = 0; i < result.Length;i++)
            {
                result[i] = source[i+4];
            }
            this.swith(id,result);
        }

        public override void swith(int id, byte[] source)
        {
            if(id == 1)
            {
                 resultCreateAccount(source);
            }
            else if (id == 2)
            {
                 resultLogin(source);
            }

            else if (id == 3)
            {
                 resultLogin(source);
            }
            else if (id == 4)
            {
                 resultLogin(source);
            }
            else if (id == 5)
            {
                resultLogin(source);
            }
                
        }
        //client to server
        public void reqCreateAccount(accountInfo info)
        {

        }
        public void reqLogin(accountInfo info)
        {

        }
        public void reqCreatePlayer(playerInfo info)
        {

        }  //此时id没有意义
        public void reqPlayerList()
        {

        }
        public void reqSelectPlayer(int id)
        {

        }

        //server to client
        //默认id == 1
        public void resultCreateAccount(byte[] source)//创建账号结果 0-成功，
        {
            //int result
            //在处理之前先把流转换成想要的数据类型,然后再处理.
            //发送数据的时候首先把数据转换成流,再首部带上当前函数的id,使用CNet中的发送函数统一发送
        }  
        //默认id == 2
        public void resultLogin(byte[] source)//登录结果 0-成功，
        {
            //int result
        }    
        //默认id == 3
        public void resultCreatePlayer(byte[] source)//创建角色结果
        {
            //int result
        }       
        //默认id == 4
        public void resultPlayerList(byte[] source) //玩家列表
        {
            //List<playerInfo> playerList
        }          
        //默认id == 5
        public void resultSelectPlayer(byte[] source)
        {
            //int result
        }
    }
}
